import { mapMutations } from "vuex";

export default {
  data() {
    return {
      commands: []
    };
  },
  methods: {
    ...mapMutations(["undo"]),
    annotator() {
      return [
        {
          title: "常规",
          default: ["arrowup"],
          function: this.moveUp,
          name: "上移批注"
        },
        {
          default: ["arrowdown"],
          function: this.moveDown,
          name: "下移批注"
        },
        {
          default: ["arrowright"],
          function: this.stepIn,
          name: "展开类别"
        },
        {
          default: ["arrowleft"],
          function: this.stepOut,
          name: "折叠类别"
        },
        {
          default: ["space"],
          name: "新批注",
          function: () => {
            if (this.currentCategory) {
              this.currentCategory.createAnnotation();
            }
          }
        },
        {
          default: ["backspace"],
          name: "删除当前批注",
          function: () => {
            if (this.currentAnnotation) {
              let currentKeypoint = this.currentAnnotation.currentKeypoint;
              if (currentKeypoint) {
                this.currentAnnotation.keypoints.deleteKeypoint(
                  currentKeypoint
                );
                this.currentAnnotation.tagRecomputeCounter++;
                this.currentAnnotation.currentKeypoint = null;
              } else {
                this.currentAnnotation.deleteAnnotation();
              }
            }
          }
        },
        {
          default: ["control", "z"],
          name: "撤消上一个操作",
          function: this.undo
        },
        {
          default: ["s"],
          name: "选择工具",
          function: () => {
            this.activeTool = "Select";
          }
        },
        {
          default: ["r"],
          name: "BBox 工具",
          function: () => {
            if (!this.$refs.polygon.isDisabled) this.activeTool = "BBox";
          }
        },
        {
          default: ["n"],
          name: "下一张图片",
          function: this.nextImage
        },
        {
          default: ["p"],
          name: "上一张图片",
          function: this.previousImage
        },
        {
          default: ["v"],
          name: "多边形工具",
          function: () => {
            if (!this.$refs.polygon.isDisabled) this.activeTool = "Polygon";
          }
        },

        {
          default: ["w"],
          name: "魔法棒工具",
          function: () => {
            if (!this.$refs.magicwand.isDisabled)
              this.activeTool = "Magic Wand";
          }
        },
        {
          default: ["k"],
          name: "关键点工具",
          function: () => {
            if (!this.$refs.magicwand.isDisabled) this.activeTool = "Keypoints";
          }
        },
        {
          default: ["b"],
          name: "画笔工具",
          function: () => {
            if (!this.$refs.brush.isDisabled) this.activeTool = "Brush";
          }
        },
        {
          default: ["e"],
          name: "橡皮擦工具",
          function: () => {
            if (!this.$refs.eraser.isDisabled) this.activeTool = "Eraser";
          }
        },
        {
          default: ["c"],
          name: "中心图像",
          function: this.fit
        },
        {
          default: ["control", "s"],
          name: "保存",
          function: this.save
        },
        {
          title: "BBox 工具快捷方式",
          default: ["escape"],
          name: "删除当前 BBox",
          function: this.$refs.bbox.deletePolygon
        },
        {
          title: "多边形工具快捷方式",
          default: ["escape"],
          name: "删除当前多边形",
          function: this.$refs.polygon.deletePolygon
        },
        {
          title: "橡皮擦工具快捷方式",
          default: ["["],
          name: "增加半径",
          function: this.$refs.eraser.increaseRadius
        },
        {
          default: ["]"],
          name: "减小半径",
          function: this.$refs.eraser.decreaseRadius
        },
        {
          title: "画笔工具快捷方式",
          default: ["["],
          name: "增加半径",
          function: this.$refs.brush.increaseRadius
        },
        {
          default: ["]"],
          name: "减小半径",
          function: this.$refs.brush.decreaseRadius
        },
        {
          title: "魔法棒工具快捷方式",
          default: ["shift", "click"],
          name: "减去选区",
          readonly: true
        }
      ];
    }
  },
  mounted() {
    if (this.$route.name === "annotate") {
      this.commands = this.annotator();
    }
  }
};
